// webpack.config.js
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')

module.exports = {
  configureWebpack: (config) => {
    config.plugins.push(
      AutoImport({
        resolvers: [ElementPlusResolver()]
      })
    )
    config.plugins.push(
      Components({
        resolvers: [ElementPlusResolver()]
      })
    )
  },
  // 以下写法无法按需导入
  // plugins: [
  //   AutoImport({
  //     resolvers: [ElementPlusResolver()],
  //   }),
  //   Components({
  //     resolvers: [ElementPlusResolver()],
  //   }),
  // ],
  // 解决跨域代理
  // devServer: {
  //   https: false,
  //   hotOnly: false,
  //   proxy: {
  //     '/api': {
  //       target: 'http://192.168.1.222:8000/api',
  //       changeOrigin: true,
  //       pathRewrite: {
  //         '^/api': ''
  //       }
  //     }
  //   }
  // },
  // 全局使用css变量名
  css: {
    loaderOptions: {
      sass: {
        // 8版本用prependData
        // 12版本用additionalData
        additionalData: `
          @import "@/styles/variables.module.scss";  // scss文件地址
          @import "@/styles/mixin.module.scss";     // scss文件地址
        `
      }
    }
  }
}
